//
//  SISSEscrowAccountApplyViewModel.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/25.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSEscrowAccountApplyViewModel.h"
#import "SISSContractCheckLabelCell.h"
#import "SISSContractTextFillInCell.h"

@implementation SISSEscrowAccountApplyViewModel

- (NSString *)plistName {
    return @"EscrowAccountApplyInfoArray";
}



- (void)registContractClass:(UITableView *)tableView {
    [super registContractClass:tableView];
    [tableView registerClass:[SISSContractTextFillInCell class] forCellReuseIdentifier:contractTextFillInCellReuseID];
    [tableView registerClass:[SISSContractCheckLabelCell class] forCellReuseIdentifier:contractCheckLabelCellReuseID];
}

- (UITableViewCell *)getCell:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
    
    NSInteger cellType = self.dataArr[indexPath.section][indexPath.row].cellType;
    if (cellType == 11) {
        SISSContractTextFillInCell *cell = [tableView dequeueReusableCellWithIdentifier:contractTextFillInCellReuseID forIndexPath:indexPath];
        cell.contractModel = self.dataArr[indexPath.section][indexPath.row];
        return cell;
    } else if (cellType == 20) {
        SISSContractCheckLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:contractCheckLabelCellReuseID forIndexPath:indexPath];
        cell.contractModel = self.dataArr[indexPath.section][indexPath.row];
        return cell;
    }
    
    return [super getCell:tableView indexPath:indexPath];
}

- (UIView *)getViewHeaderInSection:(NSInteger)section {
    
    SISSBaseView *headerView = [[SISSBaseView alloc] init];
    headerView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    UILabel *label = [[UILabel alloc] init];
    label.textColor = COLOR(0x334A60);
    label.font = [UIFont systemFontOfSize:16];
    [headerView addSubview:label];
    
    CGFloat margin = 8.0;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerView).offset(2 * margin);
        make.centerY.equalTo(headerView);
    }];
    
    NSArray *headerTextArr = @[@"甲方（卖方）", @"乙方（买方）", @"", @"资金划转条件", @"达成交易时，划转至卖方交易的资金结算账户", @"达成交易时，利息划转至帐户", @"交易资金退回的条件是(满足以下条件之一即可)", @"其他约定:"];
    
    label.text = headerTextArr[section];
    
    return headerView;
}

- (CGFloat)getHeightForHeaderInSection:(NSInteger)section {
   if (section == 2) {
        return 16;
    } else {
        return 44;
    }
}

#pragma mark -- SISSContractChooseCellDelegate 选择后的回调
- (void)contractChooseCell:(SISSContractChooseCell *)cell chooseIndex:(NSInteger)index {
    
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    
    if (indexPath.section == 3 && indexPath.row == 0) {
        if (self.dataArr[indexPath.section].count == 6) {
            [self.dataArr[indexPath.section] removeObjectAtIndex:1];
        }
        if (index == 0) { // 平面
            SISSContractModel *model = [[SISSContractModel alloc] init];
            model.cellType = 9;
            [self.dataArr[indexPath.section] insertObject:model atIndex:1];
            
        } else if (index == 5) { // 其他
            SISSContractModel *model = [[SISSContractModel alloc] init];
            model.cellType = 8;
            model.placeHolder = @"请输入其他户型类别";
            [self.dataArr[indexPath.section] insertObject:model atIndex:1];
        }
    } else if (indexPath.section == 5 && indexPath.row == 0) {
        
    }
    [self.tableView reloadData];
}

- (SISSEscrowAccountInfoModel *)dataArrToEscrowAccountInfoModelWithModel:(SISSEscrowAccountInfoModel *)model {
    model.amount = self.dataArr[2][0].array.firstObject;
    NSString *term = @"";
    if (self.dataArr[3][0].isChecked) {
        term = @"1";
    } else if (self.dataArr[3][0].isCheckedTwo) {
        term = @"2";
    } else if (self.dataArr[3][0].isCheckedThree) {
        term = @"3";
    }
    model.term = term;
    model.accountName = self.dataArr[4][0].rightStr;
    model.accountNum = self.dataArr[4][1].rightStr;
    model.interestAccountOwner = self.dataArr[5][0].rightStr;
    model.interestAccountName = self.dataArr[5][1].rightStr;
    model.interestAccountNum = self.dataArr[5][2].rightStr;
    model.month = self.dataArr[7][0].array.firstObject;
    return model;
}

@end
